<?php

namespace Observer;

class Event
{

    protected $observers;

    // 添加观察者
    public function attach(ObserverInterface $observer)
    {
        $this->observers[] = $observer;
    }

    // 删除观察者
    public function detach(ObserverInterface $observer)
    {
        $index = array_search($observer, $this->observers);
        if ($index === false || ! array_key_exists($index, $this->observers)) {
            return false;
        }
        unset($this->observers[$index]);
    }
    public function notify()
    {
        foreach ($this->observers as $observer) {
            $observer->watch();
        }
    }

}